package com.dlyk.web;

import com.dlyk.model.ClueRemark;
import com.dlyk.query.ClueRemarkQuery;
import com.dlyk.result.R;
import com.dlyk.service.ClueRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 线索备注
 */
@RestController
public class ClueRemarkController {

    @Resource
    private ClueRemarkService clueRemarkService;

    /**
     * 添加线索备注
     */
    @PostMapping("/api/clue/remark/add")
    public R addClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery) {

        int save = clueRemarkService.saveClueRemark(clueRemarkQuery);

        return save >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 根据线索id查询备注（分页查询）
     */
    @GetMapping("/api/clue/remark/list")
    public R clueRemarkList(@RequestParam("clueId") Integer clueId,
                            @RequestParam(value = "current", required = false) Integer current) {

        // required = false  表示非必须，这个参数也可以不传，不传参数，默认查询第一页
        if (current == null) {
            current = 1;
        }

        PageInfo<ClueRemark> clueRemarkPageInfo = clueRemarkService.getClueRemarkListByClueId(clueId, current);

        return R.OK(clueRemarkPageInfo);
    }

    /**
     * 编辑备注
     */
    @PutMapping("/api/clue/remark/edit")
    public R editClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery) {

        int edit = clueRemarkService.editClueRemark(clueRemarkQuery);

        return edit >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 删除备注
     */
    @DeleteMapping("/api/clue/remark/remove/{id}")
    public R removeClueRemark(@PathVariable("id") Integer id) {

        int remove = clueRemarkService.removeClueRemark(id);

        return remove >= 1 ? R.OK() : R.FAIL();
    }

}

